package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CuisineDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.CuisineModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineImpl implements CuisineDao {
    @Override
    public int add(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public int update(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public int delete(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public List<CuisineModel> findAll(CuisineModel cuisineModel) {
        String sql = "select * from cuisine";
        return setList(sql);
    }

    private List<CuisineModel> setList(String sql) {
        ResultSet resultSet = JDBC.query(sql);
        List<CuisineModel> list = new ArrayList<>();
        try {
            while (resultSet.next()) {
                CuisineModel model = new CuisineModel();
                model.setId(resultSet.getInt("id"));
                model.setName(resultSet.getString("name"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
//            JDBC.close();
        }
        return list;
    }

    @Override
    public CuisineModel findById(int id) {
        return null;
    }

    @Override
    public int changeEnable(int id) {
        return 0;
    }
}
